int inByte = 0;         // incoming serial byte
int led = 9;

void setup()
{
  pinMode(led, OUTPUT);
  digitalWrite(led, LOW);
  // start serial port at 9600 bps:
  Serial.begin(9600);
  establishContact();  // send a byte to establish contact until receiver responds
}

void loop()
{
  // if we get a valid byte, read analog ins:
  if (Serial.available() > 0) {
    // get incoming byte:
    inByte = Serial.read();
    // read first analog input, divide by 4 to make the range 0-255:
    if (inByte == 'X') {
      digitalWrite(led, HIGH);
    }
    else {
      digitalWrite(led, LOW);
    }
  }
}

void establishContact() {
  while (Serial.available() <= 0) {
    delay(300);
  }
}
